package com.binlog.control;

import com.binlog.config.BinLogDbProperty;
import com.binlog.core.BinlogSubscriptionStarter;
import com.binlog.core.container.ClintContainer;
import com.github.shyiko.mysql.binlog.BinaryLogClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping(value = "/api/client")
@Slf4j
public class ClientControl {

    @Resource
    private BinlogSubscriptionStarter binlogSubscriptionStarter;

    /**
     * 查询list
     *
     * @return
     */
    @GetMapping
    public Map<Long, BinLogDbProperty> list() {
        return ClintContainer.BINARY_LOG_PROPERTY_MAP;
    }


//    /**
//     * 查询list
//     *
//     * @return
//     */
//    @GetMapping(value = "changePosition")
//    public String changePosition(@RequestParam("serverId") Long serverId,
//                                 @RequestParam("positionId") Long positionId,
//                                 @RequestParam("positionFileName") String positionFileName) {
//        new Thread(new Runnable() {
//            @Override
//            public void run() {
//                log.info("更新position");
//                binlogSubscriptionStarter.restartClient(serverId, positionId, positionFileName);
//            }
//        }).start();
//        return "更新成功";
//    }
}
